<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Context Free LALR1 compiler: src/contextFree/scanner/LALR1.java Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Context Free LALR1 compiler
   &#160;<span id="projectnumber">1.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="dynsections.js"></script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Packages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('_l_a_l_r1_8java.html','');
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">src/contextFree/scanner/LALR1.java</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="keyword">package </span>contextFree.scanner;
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 <span class="keyword">import</span> java.util.*;
<a name="l00004"></a>00004 
<a name="l00005"></a>00005 <span class="keyword">import</span> org.apache.log4j.Logger;
<a name="l00006"></a>00006 
<a name="l00007"></a>00007 <span class="keyword">import</span> contextFree.grammar.IGrammar;
<a name="l00008"></a>00008 <span class="keyword">import</span> contextFree.grammar.Production;
<a name="l00009"></a>00009 
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="keyword">import</span> error.ERROR_TYPE;
<a name="l00012"></a>00012 <span class="keyword">import</span> error.ErrorManager;
<a name="l00013"></a>00013 
<a name="l00014"></a><a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html">00014</a> <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html">LALR1</a> <span class="keyword">extends</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html">LR0</a>{
<a name="l00015"></a>00015         <span class="keyword">static</span> Logger logger = Logger.getLogger(<a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html">LALR1</a>.class.getName());
<a name="l00016"></a>00016         
<a name="l00017"></a>00017         <span class="keyword">private</span> <span class="keywordtype">boolean</span> isAmbiguous=<span class="keyword">false</span>;
<a name="l00018"></a>00018         <span class="keyword">private</span> String ambiguo=<span class="stringliteral">&quot;&quot;</span>;
<a name="l00019"></a>00019         <span class="keyword">private</span> <a class="code" href="classcontext_free_1_1scanner_1_1_automa.html">Automa</a> automa;
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 
<a name="l00022"></a>00022         <span class="keyword">private</span> String[][] actionTable;
<a name="l00023"></a>00023         <span class="keyword">private</span> String[][] gotoTable;
<a name="l00024"></a>00024         
<a name="l00025"></a>00025         
<a name="l00026"></a>00026         <span class="keyword">public</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html">LALR1</a>(){
<a name="l00027"></a>00027                 automa=<span class="keyword">new</span> <a class="code" href="classcontext_free_1_1scanner_1_1_automa.html">Automa</a>();
<a name="l00028"></a>00028                 grammatica=null;
<a name="l00029"></a>00029         }
<a name="l00030"></a>00030         
<a name="l00031"></a>00031         <span class="keyword">public</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html">LALR1</a>(<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html" title="Grammar Interface.">IGrammar</a> gram){
<a name="l00032"></a>00032                 automa = <span class="keyword">new</span> <a class="code" href="classcontext_free_1_1scanner_1_1_automa.html">Automa</a>();
<a name="l00033"></a>00033                 setGrammar(gram);
<a name="l00034"></a>00034                 }
<a name="l00035"></a>00035         
<a name="l00036"></a>00036         <span class="keyword">public</span> String[][] getActionTable() {
<a name="l00037"></a>00037                 <span class="keywordflow">return</span> actionTable;
<a name="l00038"></a>00038         }
<a name="l00039"></a>00039 
<a name="l00040"></a>00040         <span class="keyword">public</span> <span class="keywordtype">void</span> setActionTable(String[][] actionTable) {
<a name="l00041"></a>00041                 this.actionTable = actionTable;
<a name="l00042"></a>00042         }
<a name="l00043"></a>00043 
<a name="l00044"></a>00044         <span class="keyword">public</span> String[][] getGotoTable() {
<a name="l00045"></a>00045                 <span class="keywordflow">return</span> gotoTable;
<a name="l00046"></a>00046         }
<a name="l00047"></a>00047 
<a name="l00048"></a>00048         <span class="keyword">public</span> <span class="keywordtype">void</span> setGotoTable(String[][] gotoTable) {
<a name="l00049"></a>00049                 this.gotoTable = gotoTable;
<a name="l00050"></a>00050         }
<a name="l00051"></a>00051         
<a name="l00052"></a>00052         @Override
<a name="l00053"></a>00053         <span class="keyword">public</span> <a class="code" href="classcontext_free_1_1scanner_1_1_automa.html">Automa</a> getAutoma() {
<a name="l00054"></a>00054                 <span class="keywordflow">return</span> automa;
<a name="l00055"></a>00055         }
<a name="l00056"></a>00056                 
<a name="l00057"></a>00057         @Override
<a name="l00058"></a>00058         <span class="keyword">public</span> <a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html" title="Grammar Interface.">IGrammar</a> getGrammar(){
<a name="l00059"></a>00059                 <span class="keywordflow">return</span> this.grammatica;
<a name="l00060"></a>00060         }
<a name="l00061"></a>00061         
<a name="l00062"></a>00062         
<a name="l00063"></a>00063         @Override
<a name="l00064"></a>00064         <span class="keyword">public</span> <span class="keywordtype">void</span> setGrammar(<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html" title="Grammar Interface.">IGrammar</a> gram) {
<a name="l00065"></a>00065                 grammatica=gram;
<a name="l00066"></a>00066         }
<a name="l00067"></a>00067         
<a name="l00075"></a>00075         @Override
<a name="l00076"></a><a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#a84de2247841f98c9d1339acac165d141">00076</a>         <span class="keyword">public</span> <span class="keywordtype">int</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#a84de2247841f98c9d1339acac165d141" title="Initialize the LALR(1) automaton from LR0 automaton.">init</a>() throws Exception{
<a name="l00077"></a>00077                 <span class="keywordflow">try</span>{
<a name="l00078"></a>00078                         <a class="code" href="classcontext_free_1_1scanner_1_1_automa.html">Automa</a> AutomaLR0 = <span class="keyword">new</span> <a class="code" href="classcontext_free_1_1scanner_1_1_automa.html">Automa</a>(<a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#a5c7d77fe2a994398ef6312251e2f6109" title="given a grammar G we calculate the associated grammar augmented by adding the production S &#39;:: =...">Item</a>());
<a name="l00079"></a>00079 
<a name="l00080"></a>00080                         logger.debug(<span class="stringliteral">&quot;Inizializzazione dell&#39;automa con stati contenenti i kernel LR0&quot;</span>);
<a name="l00081"></a>00081                         this.automa.setStates(AutomaLR0.<a class="code" href="classcontext_free_1_1scanner_1_1_automa.html#a7cb3536eab5b56faee50dafd8de978ad" title="Get kernels element for each states into automa.">newItemsFromKernels</a>());
<a name="l00082"></a>00082                         
<a name="l00084"></a>00084                         <span class="comment">//genera i simboli e rimuove il dollaro in tutte le produzioni ad eccezione della prima//</span>
<a name="l00085"></a>00085                         <a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#ab1c19e75693982310b7494bd3b8623c9" title="Calculate one step of lookahead symbol from an automaton with the algorithm of spontaneous generation...">calculateSymbol</a>(this.automa);
<a name="l00086"></a>00086                         this.automa.<a class="code" href="classcontext_free_1_1scanner_1_1_automa.html#aae82c530ffa9a9ea010de9eb9f77707d" title="remove dollar simbol lookahed">removeDollarLookahed</a>();
<a name="l00088"></a>00088                         
<a name="l00089"></a>00089                         <span class="keywordtype">int</span> count=1; <span class="comment">//variabile di supporto per il numero di cicli nel logger</span>
<a name="l00090"></a>00090                         <span class="keywordtype">int</span> flag=1;
<a name="l00091"></a>00091                         <span class="keywordflow">while</span>(flag!=0){
<a name="l00092"></a>00092                                 flag=0;
<a name="l00093"></a>00093                                         logger.debug(<span class="stringliteral">&quot;\nCiclo &quot;</span>+count);
<a name="l00094"></a>00094                                         flag+=<a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#ab1c19e75693982310b7494bd3b8623c9" title="Calculate one step of lookahead symbol from an automaton with the algorithm of spontaneous generation...">calculateSymbol</a>(this.automa);
<a name="l00095"></a>00095                                         count++;
<a name="l00096"></a>00096                                 }
<a name="l00097"></a>00097                         
<a name="l00098"></a>00098                         <span class="keywordflow">for</span>(<a class="code" href="classcontext_free_1_1scanner_1_1_state.html">State</a> s : this.automa.getStates()){                         <span class="comment">//Calcolo la chiusura dei kernel per completare gli stati</span>
<a name="l00099"></a>00099                                 s.setItems(<a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#a879873c5f879881494d342782387d661" title="Passed a list of production I that form the kernel of a state, return closing it, and the lookahead s...">chiusuraLR1</a>(s.getItems()));
<a name="l00100"></a>00100                         }
<a name="l00101"></a>00101                         
<a name="l00102"></a>00102                         <span class="keywordflow">if</span>(<a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#a92b63b5d61bbdd523a16aa5e577c2ba6" title="builds the Action table GoTo from an automa LALR1 and tells us if it is or not type of LALR1...">tableCostruction</a>()==1) <span class="keywordflow">return</span> 1;
<a name="l00103"></a>00103                         <span class="keywordflow">else</span> {
<a name="l00104"></a>00104                                 isAmbiguous=<span class="keyword">true</span>;
<a name="l00105"></a>00105                                 <span class="keywordflow">return</span> 0;
<a name="l00106"></a>00106                         }
<a name="l00107"></a>00107                 }<span class="keywordflow">catch</span> (Exception e) {
<a name="l00108"></a>00108                         <a class="code" href="classerror_1_1_error_manager.html">ErrorManager</a>.manage(<a class="code" href="enumerror_1_1_e_r_r_o_r___t_y_p_e.html">ERROR_TYPE</a>.LALR1_INIT,e);
<a name="l00109"></a>00109                         <span class="keywordflow">return</span> -1;
<a name="l00110"></a>00110                 }
<a name="l00111"></a>00111         }
<a name="l00112"></a>00112         
<a name="l00122"></a><a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#ab1c19e75693982310b7494bd3b8623c9">00122</a>         <span class="keyword">private</span> <span class="keywordtype">int</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#ab1c19e75693982310b7494bd3b8623c9" title="Calculate one step of lookahead symbol from an automaton with the algorithm of spontaneous generation...">calculateSymbol</a>(<a class="code" href="classcontext_free_1_1scanner_1_1_automa.html">Automa</a> atm) <span class="keywordflow">throws</span> Exception{
<a name="l00123"></a>00123                 List&lt;IndexedProduction&gt; J;
<a name="l00124"></a>00124                 <span class="keywordtype">int</span> flag = 0;
<a name="l00125"></a>00125                 <span class="keywordflow">try</span>{
<a name="l00126"></a>00126                         <span class="keywordflow">for</span>(<a class="code" href="classcontext_free_1_1scanner_1_1_state.html">State</a> s : atm.getStates()){                                                         <span class="comment">//  1.Per ogni stato dell&#39;automa </span>
<a name="l00127"></a>00127                                 <span class="keywordflow">for</span>(<a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a> K : s.getKernels()){                              <span class="comment">//      1.1 per ogni kernel dello stato</span>
<a name="l00130"></a>00130 <span class="comment"></span>                                        List&lt;IndexedProduction&gt; temp = <span class="keyword">new</span> LinkedList&lt;IndexedProduction&gt;();
<a name="l00131"></a>00131                                         temp.add(K);
<a name="l00132"></a>00132                                         J = <a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#a879873c5f879881494d342782387d661" title="Passed a list of production I that form the kernel of a state, return closing it, and the lookahead s...">chiusuraLR1</a>(temp);                                                          <span class="comment">//1.1.1 calcolo la chiusura</span>
<a name="l00133"></a>00133                                         <span class="keywordflow">for</span>(<a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a> jItem : J){                                               
<a name="l00134"></a>00134                                                 <span class="keywordflow">for</span>(String lookahead : jItem.getLookahead()){   <span class="comment">//1.1.1.1       per ogni simbolo di lookahead</span>
<a name="l00135"></a>00135                                                         Integer i;
<a name="l00136"></a>00136                                                         <a class="code" href="classcontext_free_1_1scanner_1_1_state.html">State</a> tmpState;
<a name="l00137"></a>00137                                                         <span class="keywordflow">if</span>((i=s.gotoStateIndex(jItem.getCharAfter()))!=null)    <span class="comment">//1.1.1.1.1  mi faccio dire a quale stato arrivo per un determinato simbolo</span>
<a name="l00138"></a>00138                                                         <span class="keywordflow">if</span>((tmpState = atm.getState(i))!=null){
<a name="l00139"></a>00139                                                                 <span class="keywordflow">for</span>(<a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a> p : tmpState.getItems()){         <span class="comment">//1.1.1.1.1.1 confronto ogni produzione all&#39;interno dello stato di arrivo con la produzione della chiusura J</span>
<a name="l00140"></a>00140                                                                         <span class="keywordflow">if</span>(p.compare(jItem)     &amp;&amp; 
<a name="l00141"></a>00141                                                                                         p.getCurrentCharIndex() == (jItem.getCurrentCharIndex()+1)){
<a name="l00142"></a>00142                                                                                 Set&lt;String&gt; kLook = K.getLookahead();
<a name="l00143"></a>00143                                                                                 <span class="keywordflow">if</span>(!kLook.contains(lookahead)){                         <span class="comment">//1.1.1.1.1.2 se non contiene il simbolo di lookahead corrente il simbolo viene generato per la produzione che &quot;segue&quot; nello stato successivo</span>
<a name="l00144"></a>00144                                                                                         <span class="keywordflow">if</span>(p.getLookahead().add(lookahead)) flag = 1;
<a name="l00145"></a>00145                                                                                         logger.debug(<span class="stringliteral">&quot;Simbolo [&quot;</span> + lookahead + <span class="stringliteral">&quot;] generato per &quot;</span>+ p.toString());
<a name="l00146"></a>00146                                                                                 }<span class="keywordflow">else</span>{                                                                          <span class="comment">//1.1.1.1.1.2 se contiene il simbolo di lookahead corrente i simboli della produzione in esame della chiusura vengono propagati alla produzione che &quot;segue&quot; nello stato successivo</span>
<a name="l00147"></a>00147                                                                                         <span class="keywordflow">if</span>(p.getLookahead().addAll(K.getLookahead())) flag = 1;
<a name="l00148"></a>00148                                                                                         logger.debug(<span class="stringliteral">&quot;Simboli &quot;</span>+K.getLookahead()+<span class="stringliteral">&quot; propagati da &quot;</span> + K.toString() +<span class="stringliteral">&quot;a &quot;</span>+p.toString());
<a name="l00149"></a>00149                                                                                 }
<a name="l00150"></a>00150                                                                         }
<a name="l00151"></a>00151                                                                 }       
<a name="l00152"></a>00152                                                         }                                       
<a name="l00153"></a>00153                                                 }
<a name="l00154"></a>00154                                         }
<a name="l00155"></a>00155                                 }
<a name="l00156"></a>00156                         }
<a name="l00157"></a>00157                         <span class="keywordflow">return</span> flag;
<a name="l00158"></a>00158                 }<span class="keywordflow">catch</span> (Exception e) {
<a name="l00159"></a>00159                         <a class="code" href="classerror_1_1_error_manager.html">ErrorManager</a>.manage(<a class="code" href="enumerror_1_1_e_r_r_o_r___t_y_p_e.html">ERROR_TYPE</a>.LOOKAHEAD_PROPAGATION_ERROR, e);
<a name="l00160"></a>00160                         <span class="keywordflow">return</span> -1;
<a name="l00161"></a>00161                 }
<a name="l00162"></a>00162         }
<a name="l00163"></a>00163 
<a name="l00164"></a>00164         
<a name="l00171"></a><a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#a879873c5f879881494d342782387d661">00171</a>         <span class="keyword">public</span> List&lt;IndexedProduction&gt; <a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#a879873c5f879881494d342782387d661" title="Passed a list of production I that form the kernel of a state, return closing it, and the lookahead s...">chiusuraLR1</a> (List&lt;IndexedProduction&gt; i){
<a name="l00172"></a>00172                 <span class="keywordtype">boolean</span> flag =<span class="keyword">true</span>;
<a name="l00173"></a>00173                 <span class="keywordtype">boolean</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#ace66d28273502a9daf8e4550f48b5782" title="checks if a state is present in an automaton">uguale</a> =<span class="keyword">true</span>;
<a name="l00174"></a>00174                 <a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a> item ;
<a name="l00175"></a>00175                 <a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a> item1 ;
<a name="l00176"></a>00176                 <span class="keywordtype">int</span> punto;
<a name="l00177"></a>00177                 <a class="code" href="classcontext_free_1_1grammar_1_1_production.html">Production</a> corrente;
<a name="l00178"></a>00178                 String x;
<a name="l00179"></a>00179                 String la;
<a name="l00180"></a>00180                 Object[] ob;
<a name="l00181"></a>00181                 String[] right;
<a name="l00182"></a>00182                 Set&lt;String&gt; look;
<a name="l00183"></a>00183 
<a name="l00184"></a>00184                 <span class="comment">//Copio il kernel item I in una List&lt;IndexedProduction&gt; j cosi&#39; avro&#39; sia i Kernel che i relativi Item che formano la chiusura</span>
<a name="l00185"></a>00185                 List&lt;IndexedProduction&gt; j = <span class="keyword">new</span> ArrayList&lt;IndexedProduction&gt;();
<a name="l00186"></a>00186                 j.addAll(i);
<a name="l00187"></a>00187                 <span class="comment">//fino a quando  vengono aggiunti nuovi item a J</span>
<a name="l00188"></a>00188                 <span class="keywordflow">while</span> (flag) {
<a name="l00189"></a>00189                         flag=<span class="keyword">false</span>;
<a name="l00190"></a>00190                         Iterator &lt;IndexedProduction&gt; iter = j.iterator();
<a name="l00191"></a>00191                         <span class="keywordflow">while</span>(iter.hasNext()){
<a name="l00192"></a>00192                                 <span class="comment">//per ogni Item appartenente a j</span>
<a name="l00193"></a>00193                                 item = iter.next();
<a name="l00194"></a>00194                                 <span class="comment">//_____________________________________________________________________________________________________</span>
<a name="l00195"></a>00195                                 <span class="comment">//TODO: ob = item.getRight().toArray(); right = Arrays.copyOf(ob,ob.length,String[].class);  &lt;--inutile</span>
<a name="l00196"></a>00196                                 ob = item.getRightSimbols().toArray();
<a name="l00197"></a>00197                                 right = Arrays.copyOf(ob,ob.length,String[].class);
<a name="l00198"></a>00198                                 <span class="comment">//_____________________________________________________________________________________________________</span>
<a name="l00199"></a>00199                                 <span class="comment">//Se il puntino si trova nell&#39;ultima posizione, ossia l&#39;indice di posizione � maggiore o uguale </span>
<a name="l00200"></a>00200                                 <span class="comment">//della lunghezza del Rightlist</span>
<a name="l00201"></a>00201                                 punto= item.getCurrentCharIndex();
<a name="l00202"></a>00202                                 <span class="keywordflow">if</span>(punto &gt;= item.getRightSimbols().size()){
<a name="l00203"></a>00203                                         <span class="comment">//esci dal while xk� ci troviamo nel caso chiusura e quindi non possiamo </span>
<a name="l00204"></a>00204                                         <span class="comment">//trovare alcuna produzione che ha nella parte sinistra l&#39;elemento che segue il punto</span>
<a name="l00205"></a>00205                                         <span class="comment">//quindi inseriamo nella tabella action la Reduce per la produzione giusta...</span>
<a name="l00206"></a>00206                                         <span class="comment">//ossi R = P::=aBc.</span>
<a name="l00207"></a>00207                                         <span class="comment">//se la casella � gi� occupata abbiamo un conflitto e cerchiamo di risolverlo avvalendocci dei simboli di lookahead</span>
<a name="l00208"></a>00208                                         <span class="keywordflow">break</span>;
<a name="l00209"></a>00209                                 }
<a name="l00210"></a>00210                                 <span class="comment">//prendo il simbolo che segue il puntino nella produzione [A:= a.Bc, d]</span>
<a name="l00211"></a>00211                                 x =(String) right[punto];
<a name="l00212"></a>00212                                 Iterator&lt;Production&gt; prod = grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a629ab4dc36a869b93fa239a3fee760f9" title="Get production list.">getP</a>().iterator();
<a name="l00213"></a>00213                                 <span class="comment">//per ogni produzione della grammatica </span>
<a name="l00214"></a>00214                                 <span class="keywordflow">while</span> (prod.hasNext()){
<a name="l00215"></a>00215                                         corrente=prod.next();
<a name="l00216"></a>00216                                         <span class="comment">//se il simbolo alla destra del punto e&#39; uguale alla Parte sinistra della produzione B::= z</span>
<a name="l00217"></a>00217                                         <span class="keywordflow">if</span>(x.equals(corrente.getLeft())){
<a name="l00219"></a>00219                                                 <span class="comment">//applchiamo un algoritmo simile a quello usato per calcolare il first cos� come � fatto nella teoria</span>
<a name="l00220"></a>00220                                                 look= <span class="keyword">new</span> HashSet&lt;String&gt;();
<a name="l00221"></a>00221                                                 <span class="comment">//conrtolliamo se esiste un elemento dopo il simbolo evidenziato dal punto [A:= a.Bc, d] </span>
<a name="l00222"></a>00222                                                 <span class="keywordflow">if</span>(!(punto+1 &gt;= item.getRightSimbols().size())){
<a name="l00223"></a>00223                                                         <span class="comment">//se esiste allora aggiungiamo ai simboli di lookahead i first(cd)</span>
<a name="l00224"></a>00224                                                         <span class="comment">//quindi per prima cosa controlliamo se c � un terminale o un non terminale</span>
<a name="l00225"></a>00225                                                         la = (String) right[punto+1];
<a name="l00226"></a>00226                                                         <span class="comment">//se &quot;la&quot; � un Terminale aggiungiamo il simbolo alla lista dei  lookahead per la produzione che dovremo inserire</span>
<a name="l00227"></a>00227                                                         <span class="keywordflow">if</span> (grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a996f5e0bed5a6ac469b764f56d420fb1" title="Get terminal symbols list.">getT</a>().contains(la))
<a name="l00228"></a>00228                                                                 <span class="comment">//aggiungiamo il simbolo di lookahead per la produzione che dobbiamo inserire nella chiusura</span>
<a name="l00229"></a>00229                                                                 look.add(la);
<a name="l00230"></a>00230                                                         <span class="comment">//se � un NoN Terminale aggiungiamo i first legati a quel simbolo</span>
<a name="l00231"></a>00231                                                         <span class="keywordflow">else</span>{
<a name="l00232"></a>00232                                                                 look.addAll(grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a256e9280e008a7c709ccb80725ccc0f2" title="Get the list of first for the grammar.">getFirst</a>(la));
<a name="l00233"></a>00233                                                         }
<a name="l00234"></a>00234                                                 }
<a name="l00235"></a>00235                                                 <span class="comment">//se non esiste dobbiamo inserire i simbolo di lookahead d</span>
<a name="l00236"></a>00236                                                 <span class="keywordflow">else</span>{
<a name="l00237"></a>00237                                                         look.addAll(item.<a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html#a45b191078f89a67427a2593b67ae4f1e">getLookahead</a>());
<a name="l00238"></a>00238                                                 }
<a name="l00240"></a>00240                                                 <span class="comment">//se la produzione nn e&#39; gi presente in J</span>
<a name="l00241"></a>00241                                                 uguale =<a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#a43275125600a950a4a1f78ce565eac5f" title="checks if a production is already in a list of productions.">prodPresente</a>(j, corrente);
<a name="l00242"></a>00242                                                 <span class="keywordflow">if</span>(!uguale){
<a name="l00243"></a>00243                                                         <span class="comment">//aggiungo la produzione mettendo il punto come primo elemnto B::=.Z e inserendo i nuovi termini di lookahead</span>
<a name="l00244"></a>00244                                                         j.add(<span class="keyword">new</span> <a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a>(corrente,look));
<a name="l00245"></a>00245                                                         flag=<span class="keyword">true</span>;
<a name="l00246"></a>00246                                                 }
<a name="l00247"></a>00247                                                 <span class="keywordflow">else</span>{
<a name="l00248"></a>00248                                                         <span class="comment">//se la produzione � gi� presente all&#39;interno di j dobbiamo semplicemente aggiornare i simboli di lookahead</span>
<a name="l00249"></a>00249                                                         Iterator &lt;IndexedProduction&gt; iter1 = j.iterator();
<a name="l00250"></a>00250                                                         <span class="comment">//quindi scorriamo le produzioni d j fino a quando non troviamo quella che dobbiamo modificare</span>
<a name="l00251"></a>00251                                                         <span class="keywordflow">while</span>(iter1.hasNext()){
<a name="l00252"></a>00252                                                                 <span class="comment">//per ogni Item appartenente a j</span>
<a name="l00253"></a>00253                                                                 item1 = iter1.next();
<a name="l00254"></a>00254                                                                 <span class="comment">//controllo che  sia se la parte destra che la parte sinistra sono gi� presenti</span>
<a name="l00255"></a>00255                                                                 <span class="keywordflow">if</span> (item1.getRight().equals(corrente.getRight()) &amp; item1.getLeft().equals(corrente.getLeft()))
<a name="l00256"></a>00256                                                                         {
<a name="l00257"></a>00257                                                                         <span class="comment">//quindi aggiorno i simbolii di look ahead per questa produzione e esco dal ciclo perch� ho gi� trovato quella che ci interessava</span>
<a name="l00258"></a>00258                                                                                 item1.<a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html#a45b191078f89a67427a2593b67ae4f1e">getLookahead</a>().addAll(look);
<a name="l00259"></a>00259                                                                                 <span class="keywordflow">break</span>;
<a name="l00260"></a>00260                                                                         }
<a name="l00261"></a>00261                                                         }
<a name="l00262"></a>00262                                                 }
<a name="l00263"></a>00263                                         }
<a name="l00264"></a>00264 
<a name="l00265"></a>00265                                 }
<a name="l00266"></a>00266                                 <span class="comment">//se ho aggiunto nuove produzioni devo uscire dal while(iter.hasNext()) e ricreare l&#39;iteratore sulla nuova Lista creata</span>
<a name="l00267"></a>00267                                 <span class="keywordflow">if</span>(flag)
<a name="l00268"></a>00268                                         <span class="keywordflow">break</span>;
<a name="l00269"></a>00269                         }
<a name="l00270"></a>00270                 }
<a name="l00271"></a>00271                 <span class="comment">//ritorna una lista chiusura con il kernel che la genera</span>
<a name="l00272"></a>00272                 <span class="keywordflow">return</span> j;
<a name="l00273"></a>00273         }
<a name="l00274"></a>00274         
<a name="l00283"></a><a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#a92b63b5d61bbdd523a16aa5e577c2ba6">00283</a>         <span class="keyword">public</span> <span class="keywordtype">int</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#a92b63b5d61bbdd523a16aa5e577c2ba6" title="builds the Action table GoTo from an automa LALR1 and tells us if it is or not type of LALR1...">tableCostruction</a>() throws Exception{
<a name="l00284"></a>00284                 <span class="keywordflow">try</span>{
<a name="l00285"></a>00285                         <span class="comment">//serve per vedere se ci sono stati di ambiguit�</span>
<a name="l00286"></a>00286                         <span class="keywordtype">boolean</span> esito=<span class="keyword">false</span>;
<a name="l00287"></a>00287                         <span class="comment">//inizzializzazione tabella action Goto</span>
<a name="l00288"></a>00288                         gotoTable= <span class="keyword">new</span> String[automa.size()][grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a4b1bc2134e63051dc37e693294aaeec6" title="Get non-terminal symbols list.">getV</a>().size()];
<a name="l00289"></a>00289                         <span class="comment">//inizzializzo la tabella a ERR inquanto i campi che non saranno riempiti con uno schift sono di errore</span>
<a name="l00290"></a>00290                         <span class="keywordflow">for</span>(<span class="keywordtype">int</span> h=0;h&lt;automa.size();h++)
<a name="l00291"></a>00291                                 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> k=0; k&lt;grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a4b1bc2134e63051dc37e693294aaeec6" title="Get non-terminal symbols list.">getV</a>().size();k++)
<a name="l00292"></a>00292                                         gotoTable[h][k]=<span class="stringliteral">&quot;err&quot;</span>;
<a name="l00293"></a>00293                         actionTable=<span class="keyword">new</span> String [automa.size()][grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a996f5e0bed5a6ac469b764f56d420fb1" title="Get terminal symbols list.">getT</a>().size()];
<a name="l00294"></a>00294                         <span class="comment">//inizzializzo la tabella a ERR inquanto i campi che non saranno riempiti con una reduce o uno schift sono di errore</span>
<a name="l00295"></a>00295                         <span class="keywordflow">for</span>(<span class="keywordtype">int</span> h=0;h&lt;automa.size();h++)
<a name="l00296"></a>00296                                 <span class="comment">//controllo nella lista degli shift se � presente X e in caso lo scrivo nella tabella</span>
<a name="l00297"></a>00297                                 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> k=0; k&lt;grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a996f5e0bed5a6ac469b764f56d420fb1" title="Get terminal symbols list.">getT</a>().size();k++)
<a name="l00298"></a>00298                                         actionTable[h][k]=<span class="stringliteral">&quot;err&quot;</span>;
<a name="l00299"></a>00299                         
<a name="l00300"></a>00300                         <span class="comment">//per ogni stato dell&#39;automa</span>
<a name="l00301"></a>00301                         <span class="keywordflow">for</span>(<a class="code" href="classcontext_free_1_1scanner_1_1_state.html">State</a> statoi : automa.getStates()){
<a name="l00302"></a>00302                                 <span class="comment">//vediamo se ci sono riduzioni ed eventualmente le scriviamo</span>
<a name="l00303"></a>00303                                 <span class="keywordflow">if</span>(!<a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#a909aea9ab05f3633c169e4dd20447e62" title="if the point is in the last position he wrote the reduces in the action table.">reduce</a>(statoi))
<a name="l00304"></a>00304                                 esito= <span class="keyword">true</span>;
<a name="l00305"></a>00305                                 <span class="comment">//per ogni NON TERMINALE X nella grammatica</span>
<a name="l00306"></a>00306                                 <span class="keywordflow">for</span>(String X :grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a4b1bc2134e63051dc37e693294aaeec6" title="Get non-terminal symbols list.">getV</a>()){
<a name="l00307"></a>00307                                         <span class="comment">//controllo nella lista degli shift dello stato se � presente per X</span>
<a name="l00308"></a>00308                                         <span class="keywordflow">if</span>(statoi.getShift().get(X)!=null)
<a name="l00309"></a>00309                                                 <span class="comment">//scrivo nella tabella GOTO lo scift al posto di err</span>
<a name="l00310"></a>00310                                                 gotoTable[statoi.getIndex()][grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a4b1bc2134e63051dc37e693294aaeec6" title="Get non-terminal symbols list.">getV</a>().indexOf(X)]= statoi.getShift().get(X).toString();
<a name="l00311"></a>00311                                 }
<a name="l00312"></a>00312                                 <span class="comment">//per ogni simbolo Terminale</span>
<a name="l00313"></a>00313                                 <span class="keywordflow">for</span>(String X :grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a996f5e0bed5a6ac469b764f56d420fb1" title="Get terminal symbols list.">getT</a>()){
<a name="l00314"></a>00314                                         <span class="comment">//controllo nella lista degli shift dello stato se � presente X</span>
<a name="l00315"></a>00315                                         <span class="keywordflow">if</span>(statoi.getShift().get(X)!=null)
<a name="l00316"></a>00316                                                 <span class="comment">//scrivo nella tabella ACTION lo shift </span>
<a name="l00317"></a>00317                                                 <span class="keywordflow">if</span>(!<a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#aee49a037861ca73f5380efb261517825" title="Writes the action Reduce or Scift in the Action table.">actionWrite</a>(statoi.getIndex(),statoi.getShift().get(X),grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a996f5e0bed5a6ac469b764f56d420fb1" title="Get terminal symbols list.">getT</a>().indexOf(X),<span class="stringliteral">&quot;s&quot;</span>))
<a name="l00318"></a>00318                                                         esito=<span class="keyword">true</span>;
<a name="l00319"></a>00319                                 }
<a name="l00320"></a>00320                         }
<a name="l00321"></a>00321                         <span class="keywordflow">return</span> esito? 0 : 1;
<a name="l00322"></a>00322                 }<span class="keywordflow">catch</span> (Exception e) {
<a name="l00323"></a>00323                         <a class="code" href="classerror_1_1_error_manager.html">ErrorManager</a>.manage(<a class="code" href="enumerror_1_1_e_r_r_o_r___t_y_p_e.html">ERROR_TYPE</a>.TABLE_CONSTRUCTION, e);
<a name="l00324"></a>00324                         <span class="keywordflow">return</span> -1;
<a name="l00325"></a>00325                 }
<a name="l00326"></a>00326         }
<a name="l00327"></a>00327         
<a name="l00334"></a><a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#a909aea9ab05f3633c169e4dd20447e62">00334</a>         <span class="keyword">public</span> <span class="keywordtype">boolean</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#a909aea9ab05f3633c169e4dd20447e62" title="if the point is in the last position he wrote the reduces in the action table.">reduce</a>(<a class="code" href="classcontext_free_1_1scanner_1_1_state.html">State</a> stato){
<a name="l00335"></a>00335                 <span class="comment">//serve per vedere se ci sono stati di ambiguita&#39;</span>
<a name="l00336"></a>00336                 <span class="keywordtype">boolean</span> esito=<span class="keyword">false</span>;
<a name="l00337"></a>00337                 <span class="keywordtype">boolean</span> ret=<span class="keyword">true</span>;
<a name="l00338"></a>00338                 <span class="comment">//per ogni produzione dello stato</span>
<a name="l00339"></a>00339                 <span class="keywordflow">for</span>(<a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a> prodStato : stato.<a class="code" href="classcontext_free_1_1scanner_1_1_state.html#a987d4c7ae8eb2754f13f0099f5d861a5" title="return one list&lt;IndexedProduction&gt; with the kernel of a state">getKernels</a>())
<a name="l00340"></a>00340                         <span class="comment">//se il puntino si trove nell&#39;ultima posizione ci troviamo nel caso di una reduce</span>
<a name="l00341"></a>00341                         <span class="keywordflow">if</span>(prodStato.getCurrentCharIndex()&gt;=prodStato.getRightSimbols().size()){
<a name="l00342"></a>00342                                 <span class="comment">//se si tratta della reduce [S&#39;::=S, $] e&#39; il caso dell&#39;accettazione</span>
<a name="l00343"></a>00343                                 <span class="keywordflow">if</span>(prodStato.getLeft().equals(<span class="stringliteral">&quot;S&#39;&quot;</span>)){
<a name="l00345"></a>00345                                         esito = <a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#aee49a037861ca73f5380efb261517825" title="Writes the action Reduce or Scift in the Action table.">actionWrite</a>(stato.getIndex(),-1,grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a996f5e0bed5a6ac469b764f56d420fb1" title="Get terminal symbols list.">getT</a>().indexOf(<span class="stringliteral">&quot;$&quot;</span>),<span class="stringliteral">&quot;acc&quot;</span>);
<a name="l00346"></a>00346                                         <span class="keywordflow">if</span> (!esito)
<a name="l00347"></a>00347                                                 ret=<span class="keyword">false</span>;
<a name="l00348"></a>00348                                                 
<a name="l00349"></a>00349                                 }
<a name="l00350"></a>00350                                 <span class="comment">//se no ci troviamo nel caso di una risuzione </span>
<a name="l00351"></a>00351                                 <span class="keywordflow">else</span>{
<a name="l00352"></a>00352                                         <span class="comment">//per ogni simbolo di lookahead</span>
<a name="l00353"></a>00353                                         <span class="keywordflow">for</span>(String la : prodStato.getLookahead())
<a name="l00354"></a>00354                                                 <span class="comment">//chiamo la funzione per scrivere nella tabella action</span>
<a name="l00355"></a>00355                                                 esito = <a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#aee49a037861ca73f5380efb261517825" title="Writes the action Reduce or Scift in the Action table.">actionWrite</a>(stato.getIndex(),-1,grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a996f5e0bed5a6ac469b764f56d420fb1" title="Get terminal symbols list.">getT</a>().indexOf(la),prodStato.getLeft()+<span class="stringliteral">&quot;::=&quot;</span>+prodStato.getRight());
<a name="l00356"></a>00356                                         <span class="keywordflow">if</span> (!esito)
<a name="l00357"></a>00357                                                 ret=<span class="keyword">false</span>;
<a name="l00358"></a>00358                                 }
<a name="l00359"></a>00359                         }
<a name="l00360"></a>00360                 <span class="keywordflow">return</span> ret;
<a name="l00361"></a>00361         }
<a name="l00362"></a>00362         
<a name="l00372"></a><a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#aee49a037861ca73f5380efb261517825">00372</a>         <span class="keyword">public</span> <span class="keywordtype">boolean</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#aee49a037861ca73f5380efb261517825" title="Writes the action Reduce or Scift in the Action table.">actionWrite</a>(<span class="keywordtype">int</span> i, <span class="keywordtype">int</span> j, <span class="keywordtype">int</span> x, String action){
<a name="l00373"></a>00373                 <span class="keywordtype">boolean</span> esito=<span class="keyword">false</span>;
<a name="l00374"></a>00374                 <span class="comment">//se la cella � occupata da &quot;err&quot;</span>
<a name="l00375"></a>00375                 <span class="keywordflow">if</span> (actionTable[i][x].equals(<span class="stringliteral">&quot;err&quot;</span>)){
<a name="l00376"></a>00376                         <span class="comment">//e si tratta di uno shift</span>
<a name="l00377"></a>00377                         <span class="keywordflow">if</span>(action.equals(<span class="stringliteral">&quot;s&quot;</span>))
<a name="l00378"></a>00378                                 <span class="comment">//sostituisco la String &quot;err&quot; con lo shift alla posizione j</span>
<a name="l00379"></a>00379                                 actionTable[i][x]= action + j;
<a name="l00380"></a>00380                         <span class="keywordflow">else</span>
<a name="l00381"></a>00381                                 <span class="comment">// se no sostituisco la String &quot;err&quot; con la reduce action</span>
<a name="l00382"></a>00382                                 actionTable[i][x]= action;
<a name="l00383"></a>00383                         <span class="comment">//e setto esito a true per dire che � andato tutto bene</span>
<a name="l00384"></a>00384                         esito =<span class="keyword">true</span>;
<a name="l00385"></a>00385                 }
<a name="l00386"></a>00386                 <span class="keywordflow">else</span>
<a name="l00387"></a>00387                         <span class="comment">//se no evidenzio lo stato di ambiguit�</span>
<a name="l00388"></a>00388                         <span class="keywordflow">if</span>(j&gt;=0)
<a name="l00389"></a>00389                                 ambiguo+=<span class="stringliteral">&quot;\nAmbiguita&#39; allo stato &quot;</span>+ i+<span class="stringliteral">&quot;: &quot;</span>+ actionTable[i][x]+ <span class="stringliteral">&quot;,  shift &quot;</span> + j ;
<a name="l00390"></a>00390                         <span class="keywordflow">else</span>
<a name="l00391"></a>00391                                 ambiguo+=<span class="stringliteral">&quot;\nAmbiguita&#39; allo stato &quot;</span>+ i+ <span class="stringliteral">&quot;: &quot;</span>+ actionTable[i][x]+ <span class="stringliteral">&quot;,  &quot;</span>+action;
<a name="l00392"></a>00392                 <span class="keywordflow">return</span> esito;
<a name="l00393"></a>00393         }
<a name="l00394"></a>00394         @Override
<a name="l00395"></a>00395         <span class="keyword">public</span> <span class="keywordtype">boolean</span> isAmbiguos(){
<a name="l00396"></a>00396                 <span class="keywordflow">return</span> isAmbiguous;
<a name="l00397"></a>00397         }
<a name="l00398"></a>00398         
<a name="l00399"></a>00399         
<a name="l00404"></a><a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#a452dc07f015344b3681d8e1a161d51dd">00404</a>         <span class="keyword">public</span> String <a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#a452dc07f015344b3681d8e1a161d51dd" title="Return a string with tables Goto Action.">printTable</a>(){
<a name="l00405"></a>00405                 String str=<span class="stringliteral">&quot;\n\t\tTabella ACTION\n\t&quot;</span>;
<a name="l00406"></a>00406                 <span class="comment">//stampo i simboli Terminali</span>
<a name="l00407"></a>00407                 <span class="keywordflow">for</span> (String t :grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a996f5e0bed5a6ac469b764f56d420fb1" title="Get terminal symbols list.">getT</a>())
<a name="l00408"></a>00408                         str+=t.toString()+<span class="stringliteral">&quot;\t&quot;</span>;
<a name="l00409"></a>00409                 <span class="comment">//per ogni stato</span>
<a name="l00410"></a>00410                 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;automa.size();i++){
<a name="l00411"></a>00411                         str+=<span class="stringliteral">&quot;\n&quot;</span>+i+<span class="stringliteral">&quot;\t&quot;</span>;
<a name="l00412"></a>00412                         <span class="comment">//Per ogni terminale</span>
<a name="l00413"></a>00413                         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j=0;j&lt;grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a996f5e0bed5a6ac469b764f56d420fb1" title="Get terminal symbols list.">getT</a>().size();j++)
<a name="l00414"></a>00414                                 str=str+actionTable[i][j]+<span class="stringliteral">&quot;\t&quot;</span>;
<a name="l00415"></a>00415                 }
<a name="l00416"></a>00416                 str+=<span class="stringliteral">&quot;\n\n\t\tTabella GOTO\n\t&quot;</span>;
<a name="l00417"></a>00417                 <span class="comment">//stampo i non terminali</span>
<a name="l00418"></a>00418                 <span class="keywordflow">for</span> (String t :grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a4b1bc2134e63051dc37e693294aaeec6" title="Get non-terminal symbols list.">getV</a>())
<a name="l00419"></a>00419                         str+=t.toString()+<span class="stringliteral">&quot;\t&quot;</span>;
<a name="l00420"></a>00420                 <span class="comment">//per ogni stato</span>
<a name="l00421"></a>00421                 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;automa.size();i++){
<a name="l00422"></a>00422                         str+=<span class="stringliteral">&quot;\n&quot;</span>+i+<span class="stringliteral">&quot;\t&quot;</span>;
<a name="l00423"></a>00423 <span class="comment">//                      Per ogni NON Terminale</span>
<a name="l00424"></a>00424                         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j=0;j&lt;grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a4b1bc2134e63051dc37e693294aaeec6" title="Get non-terminal symbols list.">getV</a>().size();j++)
<a name="l00425"></a>00425                                 str=str+gotoTable[i][j]+<span class="stringliteral">&quot;\t&quot;</span>;
<a name="l00426"></a>00426                 }
<a name="l00427"></a>00427                 <span class="keywordflow">return</span> str;
<a name="l00428"></a>00428         }
<a name="l00429"></a>00429 
<a name="l00430"></a>00430         @Override
<a name="l00431"></a>00431                 <span class="keyword">public</span> String toString(){
<a name="l00432"></a>00432                         <span class="keywordflow">if</span>(isAmbiguous) <span class="keywordflow">return</span> ambiguo;
<a name="l00433"></a>00433         <span class="comment">//              return &quot;Grammatica:\n&quot;+this.grammatica.toString()+ &quot;\n&quot; + this.automa.toString() + &quot;\n&quot;+printTable();</span>
<a name="l00434"></a>00434                         <span class="keywordflow">return</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_a_l_r1.html#a452dc07f015344b3681d8e1a161d51dd" title="Return a string with tables Goto Action.">printTable</a>();
<a name="l00435"></a>00435                 }
<a name="l00436"></a>00436 }
</pre></div></div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>LALR1.java</b>      </li>

    <li class="footer">Generated on Fri Mar 30 2012 21:26:23 for Context Free LALR1 compiler by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.0 </li>
   </ul>
 </div>


</body>
</html>
